package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Flags6502;
import emulator.hardware.nmos6502.commands.DEC;
import emulator.unittest.hardware.nmos6502.MockOperand;


public class DECTest {

	@Test
	public void testDecPositive() throws EmulatorException {
		executeAndCheckDEC(0x3F, 0);
	}

	@Test
	public void testDecNegative() throws EmulatorException {
		executeAndCheckDEC(0x00, Flags6502.FLAG_NEGATIVE);
	}

	@Test
	public void testDecZero() throws EmulatorException {
		executeAndCheckDEC(0x01, Flags6502.FLAG_ZERO);
	}

	private void executeAndCheckDEC(int val, int expected_flags)
			throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MockOperand operand = new MockOperand(val);
		new DEC().execute(cpu, operand);
		assertEquals(new HwByte(val-1), operand.getByte());
		assertEquals(new Flags6502(expected_flags), cpu.getFlags());
	}
}
